﻿
//餐厅状态
function orderstate(i){
	
	if(i==1) return "正常营业";
	if(i==2) return "正在装修";
	if(i==3) return "停业";
	if(i==4) return "即将开业";
	
}

//判断是否是 undefined ，如果是 则返回空，否则返回原数据
function isundefined(v){
	if(typeof(v)== 'undefined'||v==''||v=='null'||v=='undefined'||v==null) return '';
	else return v;
} 
//获取单选 radio 的值
 function   getRadioValue(objs){
	  for(var   i=0;   i<objs.length;   i++)  {  
		  if(objs[i].checked)  
		       return   objs[i].value;  
	  }  
	  return   -1;  
 }  
 
 //数字验证
function isnumber (s, goodChar){  
  var i,c;
  if( s.length == 0 )
   return "";
  for (i = 0; i < s.length; i++) {   
	    c = s.charAt(i); 	   
	   if (goodChar.indexOf(c) == -1) 
	       return c;
	}
  return "";
}
 
 
 //特殊字符的转换
var s_c= new Array();
var i=0; 
s_c[i++]=new Array("%","%");
s_c[i++]=new Array("％","%");
s_c[i++]=new Array("#","号");
s_c[i++]=new Array("＃","号");


 
 //处理特殊字符
 function dealwith_special_char(content){
 	var con='';
 		for (i=0; i<content.length; i++) {
				TempChar =dealwith_zf(content.substring(i, i +1));
				con+=TempChar;
			}
 	return con;
}
//字符循环
function dealwith_zf(c){
	var re;var f=false;
	for(var k=0;k<s_c.length;k++){
		if(s_c[k][0]==c){
			if(c=='#'||c=='＃'){
			  re=s_c[k][1];
			}	else{
				re= encodeURI(s_c[k][1]); 
			}
			f=true;
			break;
		}
	}
	if(!f) re=c;
	return re;
}
 
 
 var PubJS={
			getText:function(arg,key){
				if(arg==""){
					return key;
				}
				if(key==""){
					return arg;
				}
				if(arg.constructor==Array){
					for(var i=0;i<arg.length;i++){
						key=key.replace("${"+(i+1)+"}",arg[i]);
					}
					return key;
				}
				else{
					return key.replace("${1}",arg);
				}
			},
			
			
			isEmpty:function(v){
				if(filtertxt(v)==""){return true;}return false;
			},
			isEquals:function(a1,a2,desc,key){
				if(filtertxt(s1)!=filtertxt(s2)){alert(this.getText(desc,key));return false;}return true;
			},
			isEmail:function(v,desc,key){
				if (v.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){return true;}else{alert(this.getText(desc,key));return false;}
			},
			isEmail2:function(v){
				if (v.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){return true;}else{return false;}
			},
			checkEmailFmt:function(v){
				if (v.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){return true;}else{return false;}
			},
			checkEmailFmt2:function(v){
				if (v.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){return true;}else{return false;}
			},
			isBeginWithChar:function(v,desc,key){
				if(!new RegExp("[_a-zA-Z]","g").test(v.split("")[0])){alert(this.getText(desc,key));return false;}return true;
			},
			isBeginWithChar2:function(v){
				if(!new RegExp("[_a-zA-Z]","g").test(v.split("")[0])){return false;}return true;
			},
			isNumberAndChar:function(v,desc,key){
				if(!new RegExp("^[a-zA-Z0-9]*$","g").test(v)){alert(this.getText(desc,key));return false;}return true;
			},
			isNumberAndChar2:function(v){
				if(!new RegExp("^[a-zA-Z0-9]*$","g").test(v)){return false;}return true;
			},
			isNumber:function(v,desc,key){
				var regu="^[0-9]+$";var re=new RegExp(regu);if(v.search(re)!=-1){return true;}else{alert(this.getText(desc,key));return false;}
			},
			isNumber2:function(v){
				var regu="^[0-9]+$";var re=new RegExp(regu);if(v.search(re)!=-1){return true;}else{return false;}
			},
			checkLength:function(v,desc,minL,maxL,key){
				if(v.length<minL || v.length>maxL){
					var pub_arr=new Array();
					pub_arr[0]=desc;
					pub_arr[1]=minL;
					pub_arr[2]=maxL;
					alert(this.getText(pub_arr,key));return false;}return true;
			},
			checkLength2:function(v,minL,maxL){
				if(v.length<minL || v.length>maxL){
					var pub_arr=new Array();
					pub_arr[0]=desc;
					pub_arr[1]=minL;
					pub_arr[2]=maxL;
					return false;}return true;
			},
			checkMaxLength:function(v,desc,maxL,key){
				var pub_arr=new Array();
				pub_arr[0]=desc;
				pub_arr[1]=maxL;
				if(v.length>maxL){alert(this.getText(pub_arr,key));return false;}return true;
			},
			checkMaxLength2:function(v,maxL){
				var pub_arr=new Array();
				pub_arr[0]=desc;
				pub_arr[1]=maxL;
				if(v.length>maxL){return false;}return true;
			},
			isChecked:function(obj,desc,key){
				var sum=0;if(typeof(obj.length)=='undefined'){if(obj.checked==true){sum++;}}else{for(var i=0;i<obj.length;i++){if(obj[i].checked==true){sum++;}}}if(sum==0){alert(this.getText(desc,key));return false;}return true;
			},
			isChecked2:function(obj){
				var sum=0;if(typeof(obj.length)=='undefined'){if(obj.checked==true){sum++;}}else{for(var i=0;i<obj.length;i++){if(obj[i].checked==true){sum++;}}}if(sum==0){return false;}return true;
			},
			isEmptys:function(obj,desc,key){
				var sum=0;for(var i=0;i<obj.length;i++){if(filtertxt(obj[i].value)!=""){sum++;}}if(sum==0){alert(this.getText(desc,key));return false;}return true;
			},
			isEmptys2:function(obj){
				var sum=0;for(var i=0;i<obj.length;i++){if(filtertxt(obj[i].value)!=""){sum++;}}if(sum==0){return false;}return true;
			}
			
			
			
		}
 
 function filtertxt(str){var filterStr=str.replace(/(^\s*)|(\s*$)/g, '').replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br/>").replace(/\r/g,"");return filterStr;}
 
 
 
 //关闭弹出层
 function close_win(){
 	 	if(window.confirm("确认关闭该窗口!")==true)
 				$.nyroModalRemove();
 	
}